home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14430 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: hydro.com!news
  2. From: Terje Mathisen <Terje.Mathisen@hda.hydro.com>
  3. Newsgroups: comp.lang.c,comp.os.msdos.programer,comp.os.ms-windows.programmer.misc
  4. Subject: Re: fastest code
  5. Date: Sun, 14 Apr 1996 22:34:01 +0200
  6. Organization: Hydro
  7. Message-ID: <31716139.262D@hda.hydro.com>
  8. References: <316112A2.7D37@public.sta.net.cn> <31611AC9.7DE1@wight.hursley.ibm.com> <3162c21a.6084138@204.248.25.97> <31641DE2.31D4@halcyon.com> <31658942.99299605@204.248.25.97> <4kp41m$jhc@news.manawatu.gen.nz>
  9. NNTP-Posting-Host: 163.34.27.130
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.01 (Win95; I)
  14.  
  15. Gary Thomas wrote:
  16. > srwillrd@novia.net (William E. Kempf) wrote:
  17. > >As an example:  if the C code looked like this...
  18. > >while (condition)
  19. > >{
  20. > >   a = 10;
  21. > >   // other code that does not change a
  22. > >}
  23. > >a good optimizing compiler would move the a = 10 statement before the
  24. > >loop in the final machine code.
  25. > How about this sequence:
  26. > b = 6;
  27. > a = 5;
  28. > while (b < 4)
  29. > {
  30. >   a = 10;
  31. >   // other code that does not affect q
  32. > }
  33. > Your "optimizing" compiler would come out of that one with a == 10,
  34. > when it should be a == 5
  35.  
  36. No Way!
  37.  
  38. A good compiler would instead remove the complete while () loop, since it is obvious that it will never 
  39. be executed!
  40.  
  41. -- 
  42. -Terje Mathisen (include std disclaimer) <Terje.Mathisen@hda.hydro.com>
  43. "almost all programming can be viewed as an exercise in caching"
  44.